var gulp = require('gulp');

var uglify = require('gulp-uglify');
var concat = require('gulp-concat');

//复制文件
gulp.task('copy', () => {
    gulp.src('src/*.html')
        .pipe(gulp.dest('dest/'))
})

//合并js 并压缩
gulp.task('minjs', () => {
    gulp.src('src/js/*.js')
        .pipe(concat('minjs.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dest/js/'))
});

//合并 css
gulp.task('mincss', () => {
    gulp.src('src/style/*.css')
        .pipe(concat('mincss.css'))
        .pipe(gulp.dest('dest/css/'))
})

//压缩图片
var imagemin = require('gulp-imagemin');
gulp.task('minimage', () => {
    gulp.src('src/images/*')
        .pipe(imagemin())
        .pipe(gulp.dest('dest/images/'))
})

//监听事件
gulp.task('watch', () => {
    gulp.watch('src/js/*', ['minjs']);
    gulp.watch('src/style/*', ['mincss']);
    gulp.watch('src/images/*', ['minimage']);
})

//执行多个任务
gulp.task('default', ['copy', 'minjs', 'mincss', 'minimage'])